﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-09-13
namespace ZR.Admin.WebApi.Controllers {
    /// <summary>
    /// 设备运行记录
    /// </summary>
    [Verify]
    [Route("business/CksDeviceRunRecord")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksDeviceRunRecordController : BaseController {
        /// <summary>
        /// 设备运行记录接口
        /// </summary>
        private readonly ICksDeviceRunRecordService _CksDeviceRunRecordService;

        public CksDeviceRunRecordController(ICksDeviceRunRecordService CksDeviceRunRecordService) {
            _CksDeviceRunRecordService = CksDeviceRunRecordService;
        }

        /// <summary>
        /// 查询设备运行记录列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:list")]
        public IActionResult QueryCksDeviceRunRecord([FromQuery] CksDeviceRunRecordQueryDto parm) {
            var response = _CksDeviceRunRecordService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询设备运行记录详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:query")]
        public IActionResult GetCksDeviceRunRecord(int Id) {
            var response = _CksDeviceRunRecordService.GetInfo(Id);

            var info = response.Adapt<CksDeviceRunRecordDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加设备运行记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:add")]
        [Log(Title = "设备运行记录", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksDeviceRunRecord([FromBody] CksDeviceRunRecordDto parm) {
            var modal = parm.Adapt<CksDeviceRunRecord>().ToCreate(HttpContext);

            var response = _CksDeviceRunRecordService.AddCksDeviceRunRecord(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新设备运行记录
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:edit")]
        [Log(Title = "设备运行记录", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksDeviceRunRecord([FromBody] CksDeviceRunRecordDto parm) {
            var modal = parm.Adapt<CksDeviceRunRecord>().ToUpdate(HttpContext);
            var response = _CksDeviceRunRecordService.UpdateCksDeviceRunRecord(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除设备运行记录
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:delete")]
        [Log(Title = "设备运行记录", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksDeviceRunRecord([FromRoute] string ids) {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksDeviceRunRecordService.Delete(idArr));
        }

        /// <summary>
        /// 清空设备运行记录
        /// </summary>
        /// <returns></returns>
        [Log(Title = "设备运行记录", BusinessType = BusinessType.CLEAN)]
        [ActionPermissionFilter(Permission = "cksdeviceRunRecord:delete")]
        [HttpDelete("clean")]
        public IActionResult Clear() {
            if (!HttpContextExtension.IsAdmin(HttpContext)) {
                return ToResponse(ResultCode.FAIL, "操作失败");
            }
            return SUCCESS(_CksDeviceRunRecordService.TruncateCksDeviceRunRecord());
        }

    }
}